import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store/index.js'

Vue.use(VueRouter)

import Index from '../views/Index.vue'

const routes = [{
    path: '/',
    component: Index,
    children:[{
      path:"/",
      redirect:'/home'
    },{
      path:"/home",
      name:'Home',
      component:()=>import("../views/Home.vue")
    },{
      path:"/starclub",
      name:'StarClub',
      component:()=>import("../views/StarClub.vue")
    },{
      path:"/order",
      name:'Order',
      component:()=>import("../views/Order.vue")
    },{
      path:"/me",
      name:'Me',
      component:()=>import("../views/Me.vue")
    }]
  },{
    path:"/address",
    name:'Address',
    component:()=>import("../views/Address.vue")
  },{
    path:"/addAddress",
    name:'AddAddress',
    component:()=>import("../views/AddAddress.vue")
  },{
    path:"/addressSelect",
    name:'AddressSelect',
    component:()=>import("../views/AddressSelect.vue")
  },{
    path:"/city",
    name:'City',
    component:()=>import("../views/City.vue")
  },{
    path:"/storeInfo",
    name:'StoreInfo',
    component:()=>import("../views/StoreInfo.vue")
  },{
    path:"/feiKuai",
    name:'FeiKuai',
    component:()=>import("../views/FeiKuai.vue")
  },{
      path:"/login",
      name:'Login',
      component:()=>import("../views/Login.vue")
  }
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 设置路由守卫，如果页面不是login和首页则去登录
// router.beforeEach((to, from, next) => {
//   if (to.name === 'Login' || to.name === 'Home' || store.getters.userInfo != null) {
//     next()
//   } else {
//     next({
//       name: 'Login'
//     })
//   }
// })

export default router
